// create-api.ts
import { h, render, VNode } from 'vue'
import SponsorModal from '@/views/report/directory/SponsorModal.vue'

interface ModalInstance {
  remove(): void
  $updateProps(props: any): void
}

/**
 * 创建模态窗
 * @param fields
 * @param title
 */
export const useSponsor = (title?: string, fields?: object): VNode<ModalInstance> => {
  // 组件实例
  let formModal
  const container = document.createElement('div')
  // 移除组件
  const remove = () => {
    formModal = null
    render(null, container)
    container.remove()
  }
  formModal = h(SponsorModal, { fields, title, remove })
  render(formModal, container)
  return formModal
}
